package br.com.universidade.servlets.professor;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.universidade.bean.Professor;
import br.com.universidade.dao.ProfessorDao;
import br.com.universidade.servlets.GenericServlet;
import br.com.universidade.util.enun.ViewEnun;

@WebServlet(urlPatterns="/excluirProfessor")
public class ExcluirProfessorServlet extends GenericServlet{

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String codigo = req.getParameter(ViewEnun.Professor.ID.getValue());
	
		ProfessorDao professorDao = new ProfessorDao();
		try {
			Professor professor = professorDao.getById(Integer.parseInt(codigo), Professor.class);
			professorDao.deletar(professor);
			saveSucessMessage(req);
			req.getRequestDispatcher("pesquisarProfessor?post=true").forward(req, resp);
		} catch (Exception e) {
			saveErrorMessage(req);
			e.printStackTrace();
		}
	
	}
}
